package com.libre.config.mybatisplus;

import com.baomidou.mybatisplus.annotation.DbType;
import com.baomidou.mybatisplus.core.config.GlobalConfig;
import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
* @description   MyBatisPlus配置
* @author        庞留杰
* @date          2020/7/16 19:19
* @version       V1.0
**/
@Configuration
@MapperScan(basePackages = "com.libre.*.mapper")
public class MybatisPlusConfig {

    @Autowired
    private MyMetaObjectHandler metaHandler;

   /**
   * 功能描述: 分页插件，自动识别数据库类型
   *   MybatisPlusInterceptor（3.4）替换旧版本的PaginationInterceptor（3.1）
   * @author: 庞留杰
   * @return: PaginationInterceptor
   * @exception
   * @date: 2020/7/16 19:19
   */
    @Bean
    public MybatisPlusInterceptor mybatisPlusInterceptor() {
        MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
        interceptor.addInnerInterceptor(new PaginationInnerInterceptor(DbType.MYSQL));
        return interceptor;
    }

    /**
    * 功能描述: 自动填充功能
    * @author: 庞留杰
    * @return: GlobalConfig
    * @exception
    * @date: 2020/7/16 19:20
    */
    @Bean
    public GlobalConfig globalConfig() {
        GlobalConfig globalConfig = new GlobalConfig();
        globalConfig.setMetaObjectHandler(metaHandler);
        return globalConfig;
    }

}
